{% extends "sentry/bases/account.html" %}

{% load crispy_forms_tags %}
{% load i18n %}
{% load sentry_helpers %}

{% block title %}{% trans "Email Settings" %} | {{ block.super }}{% endblock %}

{% block main %}
  {% if request.user.has_unverified_emails %}
    <div class="alert alert-warning alert-block">
      {% trans "You have unverified emails. " %}
      <form action="{% url 'sentry-account-confirm-email-send' %}" method="post" class="email-alert-button">
        {% csrf_token %}
        <button type="submit" class="btn-link">{% trans "Resend Verification Emails." %}</button>
      </form>
    </div>
  {% endif %}

  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">Emails</h3>
    </div>
    <table class="table">
      <tbody>
      <tr>
        <td>
          {{ primary_email.email }}
          <span> (Primary)</span>
          {% if not primary_email.is_verified %}
          <span class="label verification label-warning">Unverified</span>
          {% endif %}
        </td>
        <td>
        </td>
        <td>
        </td>
      </tr>
      {% if alt_emails %}
        {% for email in alt_emails %}
        <tr>
          <td>
            {{ email.email }}
            {% if not email.is_verified %}
            <span class="label verification label-warning">Unverified</span>
            {% endif %}
          </td>
          <td style="text-align: right">
            {% if email != primary_email and email.is_verified and not user.is_managed %}
            <form action="" method="post">
              {% csrf_token %}
              <input type='hidden' name='new_primary_email' value='{{ email.email }}'>
              <button type='submit' name='primary' class='btn btn-default btn-sm'>Set as Primary Email</button>
            </form>
            {% endif %}
          </td>
          <td style="text-align:center">
            {% if email != primary_email %}
            <form action="" method="post">
              {% csrf_token %}
              <input type='hidden' name='email' value='{{ email.email }}'>
              <button type='submit' name='remove' class='btn btn-danger btn-sm remove'><span class="icon-trash"></span></button>
            </form>
            {% endif %}
          </td>
        </tr>
        {% endfor %}
      {% endif %}
      </tbody>
    </table>
  </div>
  <p class='help-block'>To use an email for <a href="{% url "sentry-account-settings-notifications" %}">notifications</a> it must be verified</p>
  <br>
  <form action="" method="post" class="">
    {% csrf_token %}
    {{ email_form|as_crispy_errors }}
    {{ email_form.alt_email|as_crispy_field }}

    {% if email_form.password %}
      {{ email_form.password|as_crispy_field }}
    {% endif %}

    <fieldset class="form-actions">
      <button type="submit" class="btn btn-primary">{% trans "Save Changes" %}</button>
    </fieldset>
  </form>
{% endblock %}
